using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using System.Collections.ObjectModel;
using Microsoft.Xna.Framework.Input;
using Evolution.GUI.Components;
using Evolution.Engine.Managers;

namespace Evolution.Engine.GUI.Components
{
    public class SizeF
    {
        public float Width = 0f;
        public float Height = 0f;

        public SizeF(float width, float height)
        {
            Width = width;
            Height = height;
        }
        public SizeF()
        {
            Width = 0;
            Height = 0;
        }
    }

    public abstract class Control
    {
        protected string _Name = "";
        protected Vector2 _Location = new Vector2();
        protected SizeF _Size = new SizeF(0, 0);
        protected string _Text = "";
        protected object _Tag = null;
        protected int _ZValue = 100;
        protected bool _Enable = false;
        protected bool _Visible = false;
        protected Form _Parent = null;
        protected bool _Focus = false;

        public bool Focus { get { return _Focus; } set { _Focus = value; } }
        public Form Parent { get { return _Parent; } set { _Parent = value; } }
        public bool Visible { get { return _Visible; } set { _Visible = value; } }
        public bool Enable { get { return _Enable; } set { _Enable = value; } }
        public Rectangle Bounds { get { return new Rectangle((int)(_Location.X + _Parent.Location.X), (int)(_Location.Y + _Parent.Location.Y), (int)_Size.Width, (int)_Size.Height); } }
        public int ZValue { get { return _ZValue; } set { _ZValue = value; } }
        public object Tag { get { return _Tag; } set { _Tag = value; } }
        public string Text { get { return _Text; } set { _Text = value; } }
        public SizeF Size { get { return _Size; } set { _Size = value; Resize(); } }

        public Vector2 Location { get { return _Location; } set { _Location = value; SetLocation(); } }

        public string Name { get { return _Name; } set { _Name = value; } }

        public Control(Form parent)
        {
            _Parent = parent;
        }

        public bool ContainsPoint(Point mousePos)
        {
            return Bounds.Contains(mousePos);
        }

        public virtual void Draw(GameTime gameTime) { }
        public virtual void Update(GameTime gameTime) { }
        public virtual void LoadContent() { }
        public virtual void OnMouseDown(MouseEventArgs e) { }
        public virtual void OnMouseUp(MouseEventArgs e)
        {
        }
        public virtual void OnKeyDown(KeyEventArgs e) { }
        public virtual void Resize() { }
        public virtual void SetLocation() { }
        public virtual void OnFocusLost() 
        {
            _Focus = false;
        }
    }

    public class ControlCollection : Collection<Control> { }
}
